package com.sd.common;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Spring容器组件
 * @author yexinming
 * @date 2020/5/2 9:07
 */
@Component
public class SpringApplicationContext {
    /**
     * Spring容器
     */
    private ApplicationContext context;
    /**
     * 构造函数
     * @param context
     */
    @Autowired
    public SpringApplicationContext(ApplicationContext context){
           this.context = context;
    }
    /**
     * 获取bean
     * @param clazz bean类型
     * @return bean实例
     */
    public <T> T getBean(Class<? extends T> clazz){
        return context.getBean(clazz);
    }
}
